package com.caseprocessing.model;

import java.util.List;

/**
 * 档案著录规则模型
 * 基于DA/T 18-1999标准实现完整的档案著录信息
 */
public class ArchivalDescription {
    
    // 密级与保管期限项（DA/T 18-1999 第9.3章）
    private SecurityLevel securityLevel;      // 密级
    private RetentionPeriod retentionPeriod; // 保管期限
    
    // 档案标识信息
    private String archiveNumber;             // 档号
    private String archiveHallCode;           // 档案馆代码  
    private String fondName;                  // 全宗名称
    private String categoryName;              // 类目名称
    
    // 载体形态项（DA/T 18-1999 第9.5章）
    private CarrierType carrierType;          // 载体类型
    private String quantity;                  // 数量及单位
    private String specifications;            // 规格
    
    // 主题词和关键词（DA/T 18-1999 第9.7.6章）
    private List<String> keywords;            // 主题词/关键词
    private List<String> subjectTerms;        // 规范化主题词
    
    // 附注与提要项（DA/T 18-1999 第9.6章）
    private List<String> notes;               // 附注信息
    private String summary;                   // 提要内容
    
    // 案卷业务信息（GB/T 9705-2008）
    private String filingUnit;               // 立档单位
    private String filingPerson;             // 立卷人
    private String reviewer;                  // 检查人
    private String filingDate;               // 立卷日期
    
    // 法律文书特有信息
    private String caseType;                  // 案件类型
    private String legalBasis;                // 法律依据
    private String enforcementStage;          // 执法阶段
    private String caseStatus;                // 案件状态
    
    public ArchivalDescription() {}
    
    // 密级枚举（DA/T 18-1999 表1）
    public enum SecurityLevel {
        PUBLIC(0, "GK", "公开"),
        DOMESTIC(1, "GN", "国内"),
        INTERNAL(2, "NB", "内部"),
        SECRET(3, "MM", "秘密"),
        CONFIDENTIAL(4, "JM", "机密"),
        TOP_SECRET(5, "UM", "绝密");
        
        private final int code;
        private final String pinyinCode;
        private final String chineseName;
        
        SecurityLevel(int code, String pinyinCode, String chineseName) {
            this.code = code;
            this.pinyinCode = pinyinCode;
            this.chineseName = chineseName;
        }
        
        public int getCode() { return code; }
        public String getPinyinCode() { return pinyinCode; }
        public String getChineseName() { return chineseName; }
    }
    
    // 保管期限枚举
    public enum RetentionPeriod {
        PERMANENT("永久"),
        LONG_TERM("长期"),
        SHORT_TERM("短期");
        
        private final String name;
        
        RetentionPeriod(String name) {
            this.name = name;
        }
        
        public String getName() { return name; }
    }
    
    // 载体类型枚举（DA/T 18-1999 第9.5.1章）
    public enum CarrierType {
        ORACLE_BONE("甲骨"),
        BRONZE_STONE("金石"),
        BAMBOO_SLIP("简牍"),
        SILK("缣帛"),
        PAPER("纸"),
        RECORD("唱片"),
        FILM("胶片"),
        TAPE("胶卷"),
        MAGNETIC_TAPE("磁带"),
        MAGNETIC_DISK("磁盘"),
        OPTICAL_DISK("光盘");
        
        private final String name;
        
        CarrierType(String name) {
            this.name = name;
        }
        
        public String getName() { return name; }
    }
    
    // Getters and Setters
    public SecurityLevel getSecurityLevel() { return securityLevel; }
    public void setSecurityLevel(SecurityLevel securityLevel) { this.securityLevel = securityLevel; }
    
    public RetentionPeriod getRetentionPeriod() { return retentionPeriod; }
    public void setRetentionPeriod(RetentionPeriod retentionPeriod) { this.retentionPeriod = retentionPeriod; }
    
    public String getArchiveNumber() { return archiveNumber; }
    public void setArchiveNumber(String archiveNumber) { this.archiveNumber = archiveNumber; }
    
    public String getArchiveHallCode() { return archiveHallCode; }
    public void setArchiveHallCode(String archiveHallCode) { this.archiveHallCode = archiveHallCode; }
    
    public String getFondName() { return fondName; }
    public void setFondName(String fondName) { this.fondName = fondName; }
    
    public String getCategoryName() { return categoryName; }
    public void setCategoryName(String categoryName) { this.categoryName = categoryName; }
    
    public CarrierType getCarrierType() { return carrierType; }
    public void setCarrierType(CarrierType carrierType) { this.carrierType = carrierType; }
    
    public String getQuantity() { return quantity; }
    public void setQuantity(String quantity) { this.quantity = quantity; }
    
    public String getSpecifications() { return specifications; }
    public void setSpecifications(String specifications) { this.specifications = specifications; }
    
    public List<String> getKeywords() { return keywords; }
    public void setKeywords(List<String> keywords) { this.keywords = keywords; }
    
    public List<String> getSubjectTerms() { return subjectTerms; }
    public void setSubjectTerms(List<String> subjectTerms) { this.subjectTerms = subjectTerms; }
    
    public List<String> getNotes() { return notes; }
    public void setNotes(List<String> notes) { this.notes = notes; }
    
    public String getSummary() { return summary; }
    public void setSummary(String summary) { this.summary = summary; }
    
    public String getFilingUnit() { return filingUnit; }
    public void setFilingUnit(String filingUnit) { this.filingUnit = filingUnit; }
    
    public String getFilingPerson() { return filingPerson; }
    public void setFilingPerson(String filingPerson) { this.filingPerson = filingPerson; }
    
    public String getReviewer() { return reviewer; }
    public void setReviewer(String reviewer) { this.reviewer = reviewer; }
    
    public String getFilingDate() { return filingDate; }
    public void setFilingDate(String filingDate) { this.filingDate = filingDate; }
    
    public String getCaseType() { return caseType; }
    public void setCaseType(String caseType) { this.caseType = caseType; }
    
    public String getLegalBasis() { return legalBasis; }
    public void setLegalBasis(String legalBasis) { this.legalBasis = legalBasis; }
    
    public String getEnforcementStage() { return enforcementStage; }
    public void setEnforcementStage(String enforcementStage) { this.enforcementStage = enforcementStage; }
    
    public String getCaseStatus() { return caseStatus; }
    public void setCaseStatus(String caseStatus) { this.caseStatus = caseStatus; }
    
    /**
     * 验证著录信息完整性
     */
    public boolean isComplete() {
        return fondName != null && !fondName.trim().isEmpty() &&
               categoryName != null && !categoryName.trim().isEmpty() &&
               archiveNumber != null && !archiveNumber.trim().isEmpty() &&
               filingUnit != null && !filingUnit.trim().isEmpty();
    }
    
    /**
     * 获取密级标识符（DA/T 18-1999格式）
     */
    public String getSecurityLevelIndicator() {
        if (securityLevel == null || securityLevel == SecurityLevel.PUBLIC) {
            return ""; // 公开级可不著录
        }
        return ".—" + securityLevel.getChineseName();
    }
    
    /**
     * 获取保管期限标识符（DA/T 18-1999格式）
     */
    public String getRetentionIndicator() {
        if (retentionPeriod == null) {
            return "";
        }
        return "：" + retentionPeriod.getName();
    }
    
    /**
     * 生成标准档号（根据具体单位规则）
     */
    public String generateStandardArchiveNumber(String year, String categoryCode, String sequenceNumber) {
        // 格式：全宗号-年度-类目号-案卷号
        return String.format("%s-%s-%s-%s", archiveHallCode, year, categoryCode, sequenceNumber);
    }
}